<?php
namespace app\common\model;
use \think\Model;

class WapUserFav extends BaseModel{
	/**
	* 列表
	*/
	public function getList($user_id="", $page = 1, $type = 'question'){
		if($type == 'question'){
			$ask_ids = model('User')->get_fav_object_ids($user_id, 'ask_fav');
			$where['ask_id']    = array('in', $ask_ids);
			$where['is_delete'] = 0;
			$where['status']    = 1;
			$order = 'field(ask_id,' . $ask_ids . ')';

			$query['page'] = $page ? $page : 1;

			$list = model('Ask')->where($where)->order($order)->paginate(10, false, ['query' => $query]);
		}else if($type == 'article'){
			$article_ids = model('User')->get_fav_object_ids($user_id, 'article_fav');
			$where['article_id']    = array('in', $article_ids);
			$where['is_delete'] = 0;
			$where['status']    = 1;
			$order = 'field(article_id,' . $article_ids . ')';
			$query['page'] = $page ? $page : 1;
			$list = model('Article')->where($where)->order($order)->paginate(10, false, ['query' => $query]);
		}

		return $list ? $list : array();
	}
}